
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>总部</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>
<script src="${pageContext.request.contextPath}/js/city2.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/citySelect2.js"></script>

</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<style>
.main_div {
	min-width: 1000px;
	min-height: 60px
}

.force-overflow1-1 {
	border: none
}

.buttonPic>span {
	color: #FFFFFF;
	font-size: 36px
}

.countyVipCount {
	font-size: 18px;
	line-height: 50px
}

.countyVipCount span {
	color: red
}

.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}

.anotherDetaile {
	width: 1000px;
	height: 160px;
	margin: 0 auto
}

.anotherDetaileButton {
	width: 20%;
	height: 100%;
	float: left
}
</style>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>直营商家管理</span>
					</div>
					<form id="uploadForm" class="form-horizontal"
						style="margin-top: 30px" enctype="multipart/form-data">
						<div class="form-group">
							<label class="col-xs-4 control-label">商家名称</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" name="directName">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">法人</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="superHost"
									name="userName" placeholder="法人">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">法人身份证号</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="userCard"
									name="userCard" placeholder="身份证号">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">联系电话</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="phone" name="phone"
									placeholder="联系电话">
									<input type="text" class="form-control" id="directId" name="id"
									style="display: none">
							</div>
						</div>						
						<div class="form-group">
							<label class="col-xs-4 control-label">地址</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="superAddress"
									name="address" placeholder="请输入准确的超市地址"> 
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">商家介绍</label>
							<div class="col-xs-4">
								<textarea class="col-xs-12" rows="5" id="merchantIntroduce" name="merchantIntroduce"></textarea>
							</div>
						</div>
						<div class="anotherDetaile">
							<div class="anotherDetaileButton">
								营业执照图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image2"
										alt="未选择图片" />
								</div>
								<input type="file" name="licenseFile"
									onchange="selectImage2(this)" style="width:200px">
							</div>
							<div class="anotherDetaileButton">
								法人身份证图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image3"
										alt="未选择图片" />
								</div>
								<input type="file" name="identityCardFile"
									onchange="selectImage3(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								商标专利图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image4"
										alt="未选择图片" />
								</div>
								<input type="file" name="brandFile"
									onchange="selectImage4(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								QS标示图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image5"
										alt="未选择图片" />
								</div>
								<input type="file" name="qsImgFile"
									onchange="selectImage5(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								官方授权证书
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image1"
										alt="未选择图片" />
								</div>
								<input type="file" name="accreditFile"
									onchange="selectImage1(this)" style="width:200px">

							</div>
							<div class="form-group">
							<div class="col-xs-4 col-xs-offset-5">
								<button onclick="submitSuper()" class="col-xs-6 btn btn-primary"
									type="button">修改</button>
							</div>
						</div>
						</div>
					</form>
				</div>
			</div>
		</section>

	</div>
	<script>
		$(function() {
			selection()
		})
		function selection() {
			var URL = document.location.toString();
			var sperIDs = URL.split("=")[1];
			$("#directId").val(sperIDs);
			$.post(urls + "directAction/getDirectInfo",
				{
					pageNum : 1,
					pageCount : 1,
					id : sperIDs
				},
				function(data) {
					var arr = data.list[0];
					$("input[name='directName']").val(arr.directName)
					$("input[name='address']").val(arr.address)
					$("input[name='userName']").val(arr.userName)
					$("input[name='phone']").val(arr.phone)
					$("input[name='userCard']").val(arr.userCard)
					$("#merchantIntroduce").val(arr.merchantIntroduce)
					$("#image1").attr("src","/directs/"+arr.accreditImg)
					$("#image2").attr("src","/directs/"+arr.licenseImg)
					$("#image3").attr("src","/directs/"+arr.identityCardImg)
					$("#image4").attr("src","/directs/"+arr.brandImg)
					$("#image5").attr("src","/directs/"+arr.qsImg)				
				}
				, 'json'
			)
		}
		function submitSuper() {
			//$("#passwordOn").val($.md5($("#surePassword").val()))
			//alert($("#passwordOn").val())
			var allInput = $("#uploadForm").find("input");
			
			var config = true;
			for (var ids = 0; ids < allInput.length-5; ids++) {
				if (allInput[ids].value) {
				} else {
					config = false;
				}
			}
			if (config) {
				/********************用于判断图片大小以及图片名称是否合法******************/
				var aarr = document.getElementsByTagName("input");
				var barr = [];
				var picreg = /^[A-Za-z0-9\.]{1,100}$/; //图片名称正则
				var flag1 = false; //用于判断图片大小
				var flag2 = false; //用于判断图片名称
				for (var i = 0; i < aarr.length; i++) {
					if (aarr[i].type == "file") {
						barr.push(aarr[i])
					}
				}
				
				for (var z = 0; z < barr.length; z++) {
				if(barr[z].files[0]){
					if (barr[z].files[0].size > 200000) { //判断图片大小是否大于200kb
						flag1 = true;
					}
					if (!picreg.test(barr[z].files[0].name)) { //判断图片大小是否大于200kb
						flag2 = true;
					}
					}
				}
				if (flag1) {
					alert("上传图片不得超过200kb每张");
					return;
				}
				if (flag2) {
					alert("图片名称只能由字母与数字组成");
					return;
				}
				/******************用于判断图片大小以及图片名称是否合法****************/
				if ($("#setPassword").val() == $("#surePassword").val()) {
					$.ajax({
						url : urls + "directAction/updateDirectInfoAll",
						type : 'POST',
						cache : false,
						data : new FormData($('#uploadForm')[0]),
						processData : false,
						contentType : false
					}).done(function(res) {
						if (res == true) {
							alert("提交成功")
						//$("#motai").css("display", "none");
						//$("#main").css("display", "block");
						} else if (res == false) {
							alert("提交失败")
						} else if (res == "251") {
							alert("商家名称重复，无法开通商家")
						}
					}).fail(function(res) {
						//console.log(res)
						alert("申请失败，服务器异常，请查看信息是否正确")
					});
				} else {
					alert("两次密码输入不一致")
				}
			} else {
				alert("提交失败，请填写完商家信息")
			}
	
		}
		
		function selectImage2(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image2').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage3(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image3').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage5(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image5').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage4(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image4').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage1(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image1').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
	</script>
</body>
</html>